<?php
/**
 *
 * PHP versions 5
 *
 * Copyright (C)
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of ERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software
 * Fundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 *
 * @author Bastian Schröder <bs@chemanet.de>
 * @version 2007-08-06
 * @package rail
 */

require_once( 'railadmin.conf.php' );
require_once( "$cfg_pahToPHPrail/rail_connector.class.php" );

session_start();

$rail = new rail_connector( $_SESSION["mysql_db"], $_SESSION["mysql_user"], $_SESSION["mysql_passwd"], $_SESSION["mysql_host"] );
$rail->login( isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : 'guest', isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : 'guest');

$smarty = new rail_smarty();
$smarty->caching = false;


/* ------------------------------------ Listener -------------------------------------- */
if( isset($_POST['exec']) ){
	try{
		$output = array();
		$exec = str_replace('echo', '$output[]=',
			str_replace('print_r', '$output[]=',
				str_replace('print', '$output[]=', $_POST['exec'])
			)
		);
		$time = microtime();
		eval( $exec );
		$time = microtime() - $time;
	}
	catch( Exception $e ){
		$output = $e;
	}

	$smarty->assign( array(
		'haseval' => true,
		'executiontime' => sprintf("%0.3f", $time),
		'php_code' => nl2br( str_replace(' ', '&nbsp;', $_POST['exec']) ),
		'output' => $output
	));
}


/* -------------------------------------- Display ------------------------------------- */
$smarty->display( 'rail_shell.tpl' );

?>